< previous page page_86 next page >

Page 86
You have now completed the procedure for opening the BOOKS5.MDB database and creating a Dynaset from the Authors table. The database and the Dynaset will be opened exclusively for read-only access. Only one thing is missing. You must first make sure the OpenDB procedure is executed! Place the following code line in the Form_Load procedure:
Sub Form_Load ()
   OpenDB ' open the database, set dynaset
End Sub
Now save the project and run the program. If you get an error report, review the code examples and then make the necessary changes before going on to the next section, where you'll add a few more routines that illustrate how data control methods work.
Data Control Methods
Most Visual Basic controls have associated methods. Each method can be thought of as a function or process that you can tell the program to run. The Visual Basic data control has several methods, but only three are database related. Here's a list of them:
·Refresh
·UpdateControls
·UpdateRecord
You have used the Refresh method in today's example already. This method is used any time you change any of the properties of the data control. Using the Refresh method updates the data control and forces it to rebuild the Dynaset. This refresh updates not only the behaviors and properties of the Dynaset but also the records in the set. If records are added to the table by another user after your program has created its Dynaset, invoking the Refresh method will make sure your Dynaset contains the most recent records.
The UpdateControls method is used to update any bound input controls. Invoking the UpdateControls method is the same as reading the current record and putting the values in the fields of the data table into the input controls on a form. This happens automatically each time you press the arrow buttons on the data control. But you can force the update to occur any time during the data entry process. It's especially handy if you want to undo user changes to a data record.
Now, add a single field to the form and test the UpdateControls method. Add a text box control to the form and set the DataSource property to Data1. You'll set the DataField property using Visual Basic code in a moment; leave it blank for now. Refer to Figure 4.2 for positioning and sizing the control.

 
< previous page page_86 next page >

If you like this book, buy it!